import os

original_file = '/home/sean/data/ILSVRC/ImageSets/VID/train.txt'
no_object_file = '/home/sean/data/ILSVRC/ImageSets/VID/train_no_object.txt'
write_file = '/home/sean/data/ILSVRC/ImageSets/VID/train_video_remove_no_object.txt'
video_pre = ' '
frame_num = 0
no_object_num = 0
with open(no_object_file, 'r') as nof:
     no_object_lines = nof.readlines()

# print(no_object_lines)
with open(write_file, 'w') as wf:
    for line in open(original_file):
        path = line.split(' ')[0]
        if path+'\n' in no_object_lines:
            # print(path)
            no_object_num += 1
            continue
        else:
            line_split = line.split('/')
            video = line_split[0] + '/' + line_split[1]
            frame_num += 1

        if video != video_pre:
            if video_pre != ' ':
                wf.write(' '+str(frame_num-1)+'\n')
            wf.write(video)
            video_pre = video
            frame_num = 1

    wf.write(' ' + str(frame_num))

print(no_object_num)